<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"PJ-3-1");
mysql_select_db($database_con_gl, $con_gl);
$query_klas = "SELECT kd, klasifikasi, keterangan, neraca, ruglab, tipe FROM gl_klas where tipe = 4 ORDER BY kd,klasifikasi ASC";
$klas = mysql_query($query_klas, $con_gl) or die(mysql_error());
$row_klas = mysql_fetch_assoc($klas);
$totalRows_klas = mysql_num_rows($klas);

mysql_select_db($database_con_gl, $con_gl);
$query_klas2 = "SELECT kd, klasifikasi, keterangan, neraca, ruglab, tipe FROM gl_klas where tipe = 6 ORDER BY kd,klasifikasi ASC";
$klas2 = mysql_query($query_klas2, $con_gl) or die(mysql_error());
$row_klas2 = mysql_fetch_assoc($klas2);
$totalRows_klas2 = mysql_num_rows($klas2);

mysql_select_db($database_con_gl, $con_gl);
$query_def_ak = "SELECT gl_company.a_hpp, a_piu FROM gl_company";
$def_ak = mysql_query($query_def_ak, $con_gl) or die(mysql_error());
$row_def_ak = mysql_fetch_assoc($def_ak);
$totalRows_def_ak = mysql_num_rows($def_ak);

mysql_select_db($database_con_gl, $con_gl);
$query_kontak = "SELECT id, nama, type FROM gl_kontak where gl_kontak.type <>'Supplier' ORDER BY type, nama ASC";
$kontak = mysql_query($query_kontak, $con_gl) or die(mysql_error());
$row_kontak = mysql_fetch_assoc($kontak);
$totalRows_kontak = mysql_num_rows($kontak);

// ---
mysql_select_db($database_con_gl, $con_gl);
$query_gudang = "SELECT id, gudang FROM gl_gudang";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gudang .= " where id='$_SESSION[lokasi]'";
}
$query_gudang .=" ORDER BY gudang ASC";
$gudang = mysql_query($query_gudang, $con_gl) or die(mysql_error());
$row_gudang = mysql_fetch_assoc($gudang);
$totalRows_gudang = mysql_num_rows($gudang);

mysql_select_db($database_con_gl, $con_gl);
$query_satuan = "SELECT id, satuan FROM gl_satuan ORDER BY satuan ASC";
$satuan = mysql_query($query_satuan, $con_gl) or die(mysql_error());
$row_satuan = mysql_fetch_assoc($satuan);
$totalRows_satuan = mysql_num_rows($satuan);

mysql_select_db($database_con_gl, $con_gl);
$query_kelom = "SELECT id, kelompok FROM gl_kelompok where jual=1 ORDER BY kelompok ASC";
$kelom = mysql_query($query_kelom, $con_gl) or die(mysql_error());
$row_kelom = mysql_fetch_assoc($kelom);
$totalRows_kelom = mysql_num_rows($kelom);
?>
<link rel="stylesheet" type="text/css" href="css/ui.datepicker.css"/>
<script type="text/javascript" src="js/ajax_data.js"></script>
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript">
<!--
$(function()
      {
        $('.calendar').datepicker({
            appendText : "yyyy/mm/dd",
            dateFormat : 'yy/mm/dd'
          });
      });
</script>
<script type="text/javascript">
$(document).ready(function() {

	$().ajaxStart(function() {
		$('#loading').show();
		$('#result').hide();
	}).ajaxStop(function() {
		$('#loading').hide();
		$('#result').fadeIn('slow');
	});

	$('#add').submit(function() {
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data) {
				$('#result').html(data);
			}
		})
		return false;
	});
  $('#result').click(function(){
  $(this).hide();
  });
})
</script>
<div id="loading" style="display:none;"><img src="images/loading.gif" alt="loading..." /></div>
<div id="result" style="display:none;"></div>
<h1>Tambah Retur Penjualan</h1>
<form action="proses/returpenjualan.php?act=add" method="POST" name="add" id="add">
  <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
    <tr valign="top">
      <td width="12%" align="right">Akun *: </td>
      <td width="32%">        <label>
          <select name="akun" id="akun">
            <?php
do {  
?>
            <?php
mysql_select_db($database_con_gl, $con_gl);
$query_akun = "SELECT id, akun, klasifikasi, keterangan FROM gl_akun where klasifikasi = '$row_klas[kd]' ORDER BY id,akun ASC";
$akun = mysql_query($query_akun, $con_gl) or die(mysql_error());
$row_akun = mysql_fetch_assoc($akun);
$totalRows_akun = mysql_num_rows($akun);
?>
            <option value="" style="background:#EEEEEE; font-weight:bold;"><?php echo $row_klas['klasifikasi'];?></option>
            <?php do { ?>
            <option value="<?php echo $row_akun['id']?>" <?php if($row_def_ak['a_hpp']==$row_akun['id']) { ?>selected="selected"<?php } ?>>-<?php echo $row_akun['akun']?></option>
            <?php } while ($row_akun = mysql_fetch_assoc($akun));?>
            <?php
} while ($row_klas = mysql_fetch_assoc($klas));
  $rows = mysql_num_rows($klas);
  if($rows > 0) {
      mysql_data_seek($klas, 0);
	  $row_klas = mysql_fetch_assoc($klas);
  }
?>
          </select>
        </label>      </td>
      <td width="12%" align="right">Akun Piutang *: </td>
      <td width="47%"><label>
        <select name="akunhutang" id="akunhutang">
          <?php
do {  
?>
          <?php
mysql_select_db($database_con_gl, $con_gl);
$query_akun2 = "SELECT id, akun, klasifikasi, keterangan FROM gl_akun where klasifikasi = '$row_klas2[kd]' ORDER BY id,akun ASC";
$akun2 = mysql_query($query_akun2, $con_gl) or die(mysql_error());
$row_akun2 = mysql_fetch_assoc($akun2);
$totalRows_akun2 = mysql_num_rows($akun2);
?>
          <option value="" style="background:#EEEEEE; font-weight:bold;"><?php echo $row_klas2['klasifikasi'];?></option>
          <?php do { ?>
          <option value="<?php echo $row_akun2['id']?>" <?php if($row_def_ak['a_piu']==$row_akun2['id']) { ?>selected="selected"<?php } ?>>-<?php echo $row_akun2['akun']?></option>
          <?php } while ($row_akun2 = mysql_fetch_assoc($akun2));?>
          <?php
} while ($row_klas2 = mysql_fetch_assoc($klas2));
  $rows2 = mysql_num_rows($klas2);
  if($rows2 > 0) {
      mysql_data_seek($klas2, 0);
	  $row_klas2 = mysql_fetch_assoc($klas2);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top">No. Referensi *:</td>
      <td valign="top"><div id="refDiv">
        <label>
        <input name="noreferensi" type="text" id="noreferensi" value="SR<?php echo time();?>" size="20" maxlength="20" onchange="cekReferensi(this.value);"/>
        </label>
      </div></td>
      <td align="right" valign="top">Lokasi Kantor *:</td>
      <td valign="top"><select name="gudang" id="gudang" onChange="cekReturPembelianAvailable();">
        <?php
do {  
?>
        <option value="<?php echo $row_gudang['id']?>"><?php echo $row_gudang['gudang']?></option>
        <?php
} while ($row_gudang = mysql_fetch_assoc($gudang));
  $rows = mysql_num_rows($gudang);
  if($rows > 0) {
      mysql_data_seek($gudang, 0);
	  $row_gudang = mysql_fetch_assoc($gudang);
  }
?>
      </select></td>
    </tr>
    <tr>
      <td align="right" valign="top">Tanggal *:</td>
      <td valign="top"><label></label>
      <input name="tanggal" type="text" class="calendar" id="tanggal" value="<?php echo date("Y/m/d");?>" size="20" maxlength="15"/></td>
      <td align="right" valign="top">Dari *:</td>
      <td valign="top"><label>
        <select name="dari" id="dari" onchange="setKeterangan(this.value);cekReturPenjualanAvailable();">
          <option value="">Pilih Kontak</option>
          <?php
do {  
?>
          <option value="<?php echo $row_kontak['id']?>"><?php echo $row_kontak['nama']?> ( <?php echo $row_kontak['type']; ?> )</option>
          <?php
} while ($row_kontak = mysql_fetch_assoc($kontak));
  $rows = mysql_num_rows($kontak);
  if($rows > 0) {
      mysql_data_seek($kontak, 0);
	  $row_kontak = mysql_fetch_assoc($kontak);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top">&nbsp;</td>
      <td valign="top">&nbsp;</td>
      <td align="right" valign="top">Keterangan :</td>
      <td valign="top"><div id="divKeterangan">
        <textarea name="keterangan" cols="40" rows="2" id="keterangan">Daftar Transaksi Jurnal Retur Penjualan</textarea>
      </div></td>
    </tr>
    <tr>
      <td colspan="4" align="right"><div id="ajaxDiv">
        <table width="100%" border="0" cellspacing="0" cellpadding="5" class="datatable">
          <tr>
            <th width="25%" align="center"><strong>Barang</strong></th>
            <th width="9%" align="center"><strong>Satuan</strong></th>
            <th width="10%" align="center"><strong>Jumlah</strong></th>
            <th width="10%" align="center"><strong>Harga Satuan </strong></th>
            <th width="9%" align="center"><strong>Diskon</strong></th>
            <th width="10%" align="center"><strong>Total</strong></th>
            <th align="center"><strong>Transaksi
              <input name="totalretur" type="hidden" id="totalretur" value="0" />
            </strong></th>
            <th width="15%" align="center"><strong>Aksi</strong></th>
          </tr>
          <tr valign="top" bgcolor="#FFFFFF">
            <td align="center" ><label>
              <select name="barang" id="barang" style="width:400px;" onChange="cekReturPenjualanAvailable();">
                <?php
do {  
mysql_select_db($database_con_gl, $con_gl);
$query_getpro = "SELECT id, barang, keterangan FROM gl_barang where kelompok='$row_kelom[id]' order by barang";
$getpro = mysql_query($query_getpro, $con_gl) or die(mysql_error());
$row_getpro = mysql_fetch_assoc($getpro);
$totalRows_getpro = mysql_num_rows($getpro);
?>
                <?php
 if($totalRows_getpro  > 0) { ?>
                <option value="" style="background:#DDDDDD;font-weight:bold;"><?php echo $row_kelom['kelompok']?></option>
                <?php do { ?>
                <option value="<?php echo $row_getpro['id']; ?>" title="<?php echo $row_getpro['keterangan']; ?>">-<?php echo $row_getpro['barang']; ?></option>
                <?php }  while ($row_getpro = mysql_fetch_assoc($getpro)); ?>
                <?php } ?>
                <?php
} while ($row_kelom = mysql_fetch_assoc($kelom));
  $rows = mysql_num_rows($kelom);
  if($rows > 0) {
      mysql_data_seek($kelom, 0);
	  $row_kelom = mysql_fetch_assoc($kelom);
  }
?>
              </select>
            </label></td>
            <td align="center" ><label>
              <select name="satuan" id="satuan" onChange="cekReturPenjualanAvailable();">
                <?php
do {  
?>
                <option value="<?php echo $row_satuan['id']?>"><?php echo $row_satuan['satuan']?></option>
                <?php
} while ($row_satuan = mysql_fetch_assoc($satuan));
  $rows = mysql_num_rows($satuan);
  if($rows > 0) {
      mysql_data_seek($satuan, 0);
	  $row_satuan = mysql_fetch_assoc($satuan);
  }
?>
              </select>
            </label></td>
            <td align="center" ><label>
              <input name="jumlah" type="text" id="jumlah" onchange="javascript:this.form.total.value=(this.form.jumlah.value * this.form.hargasatuan.value) - (this.form.jumlah.value * this.form.hargasatuan.value * this.form.diskon.value / 100);" size="5" maxlength="5"/>
            </label></td>
            <td align="center" ><label>
              <input name="hargasatuan" type="text" id="hargasatuan" onchange="javascript:this.form.total.value=(this.form.jumlah.value * this.form.hargasatuan.value) - (this.form.jumlah.value * this.form.hargasatuan.value * this.form.diskon.value / 100);" size="10" maxlength="10"/>
            </label></td>
            <td align="center" ><label>
              <input name="diskon" type="text" id="diskon" onchange="javascript:this.form.total.value=(this.form.jumlah.value * this.form.hargasatuan.value) - (this.form.jumlah.value * this.form.hargasatuan.value * this.form.diskon.value / 100);" value="0" size="2" maxlength="3"/>
              </label>
              %</td>
            <td align="center" ><label>
              <input name="total" type="text" id="total" size="10" maxlength="15"/>
            </label></td>
            <td align="center" ><label>
              <textarea name="transaksi" cols="40" rows="2" id="transaksi"></textarea>
            </label></td>
            <td align="center" ><div id="boxRetur"><label></label>
                  <label>
                  <img src="images/delete.png" border="0"/><input name="xx_ref" type="hidden" id="xx_ref" value="" />
                </label></div></td>
          </tr>
        </table>
      </div></td>
    </tr>
    <tr>
      <td align="left"><em>*Harus diisi</em></td>
      <td colspan="3" align="right"><input name="jenis" type="hidden" id="jenis" value="7r" />
          <label>
          <input name="Save" type="submit" id="Save" value="Simpan Retur" />
        </label></td>
    </tr>
  </table>
</form>
